rm(list = ls())
source("code/_preamble.R")

#_____________________________
##Load the dataset
placebo_check <- read_rds("data/parallel_trend.Rds")

#_____________________________
##Table A2
dvs <- c("akp_per", "hdp_per", "turnout")
main_res <- feols(.[dvs] ~ placebo_treatment  | neighborhood + election, cluster = ~ neighborhood, data = placebo_check) 
control_res <- feols(.[dvs] ~ placebo_treatment | neighborhood + election, cluster = ~ neighborhood, data = placebo_check[placebo_check$to_keep == 1, ]) 
duration_control_res <- feols(.[dvs] ~ placebo_treatment  | neighborhood + election, cluster = ~ neighborhood, data = placebo_check[placebo_check$to_keep_dur == 1, ]) 

#_____________________________
##printing the table
to_print <- rbind(
  round(c(main_res$`lhs: akp_per`$coefficients[["placebo_treatment"]], control_res$`lhs: akp_per`$coefficients[["placebo_treatment"]], duration_control_res$`lhs: akp_per`$coefficients[["placebo_treatment"]]), 3),
  str_c("(", round(c(main_res$`lhs: akp_per`$se[["placebo_treatment"]], control_res$`lhs: akp_per`$se[["placebo_treatment"]], duration_control_res$`lhs: akp_per`$se[["placebo_treatment"]]), 3), ")"),
  round(c(main_res$`lhs: hdp_per`$coefficients[["placebo_treatment"]], control_res$`lhs: hdp_per`$coefficients[["placebo_treatment"]], duration_control_res$`lhs: hdp_per`$coefficients[["placebo_treatment"]]), 3),
  str_c("(", round(c(main_res$`lhs: hdp_per`$se[["placebo_treatment"]], control_res$`lhs: hdp_per`$se[["placebo_treatment"]], duration_control_res$`lhs: hdp_per`$se[["placebo_treatment"]]), 3), ")"),
  round(c(main_res$`lhs: turnout`$coefficients[["placebo_treatment"]], control_res$`lhs: turnout`$coefficients[["placebo_treatment"]], duration_control_res$`lhs: turnout`$coefficients[["placebo_treatment"]]), 3),
  str_c("(", round(c(main_res$`lhs: turnout`$se[["placebo_treatment"]], control_res$`lhs: turnout`$se[["placebo_treatment"]], duration_control_res$`lhs: turnout`$se[["placebo_treatment"]]), 3), ")"),
  c(main_res$`lhs: akp_per`$nobs, control_res$`lhs: akp_per`$nobs, duration_control_res$`lhs: akp_per`$nobs)
)
print(xtable(to_print, digits = 3), include.rownames = F)


